"""
@name : 7.多进程-进程池-pool
@author : wenyao
@projectname: sanchuanglianxi
"""
from multiprocessing import Pool, current_process
import time
lst = []
def task(i):
    print(current_process().name, i, "start")
    # lst.append(i)
    time.sleep(2)
    # print(lst)
    print(i,"process end")
#
if __name__ == "__main__":
    #多进程建议设置与cpu核数一致
    p = Pool(processes=4,maxtasksperchild=2)
    pool_lst = []
    for i in range(20):
        p.apply_async(func = task,args=(i,))
    #池子不再接收任务
    p.close()
    #等待子进程执行完毕后 再关闭进程池
    p.join()


